package com.atguigu.lease.common.exception;

import com.atguigu.lease.common.result.ResultCodeEnum;
import lombok.Getter;

/**
 * Package: com.atguigu.lease.common.exception
 *
 * @Description:
 * @Author xiongkunYang
 * @Create 2025/4/25 14:06
 */
@Getter
public class LeaseException extends RuntimeException {
    //异常状态码
    private final Integer code;

    /**
     * 通过状态码和错误消息创建异常对象
     *
     * @param message 错误消息
     * @param code    异常状态码
     */
    public LeaseException(String message, Integer code) {
        super(message);
        this.code = code;
    }

    /**
     * 根据响应结果枚举对象创建异常对象
     *
     * @param resultCodeEnum 响应结果枚举对象
     */
    public LeaseException(ResultCodeEnum resultCodeEnum) {
        super(resultCodeEnum.getMessage());
        this.code = resultCodeEnum.getCode();
    }

    public LeaseException(String message, Exception e) {
        super(message + "-" + e.getCause() + ": " + e.getMessage());
        this.code = ResultCodeEnum.FAIL.getCode();
    }

    @Override
    public String toString() {
        return "LeaseException{" +
                "code=" + code +
                ", message=" + this.getClass().getName() + ": " +
                this.getMessage() + ", " + this.getCause() +
                '}';
    }
}
